package com.domain.oa.controller;


import com.domain.oa.entity.Role;
import com.domain.oa.entity.RoleMenu;
import com.domain.oa.service.RoleService;
import com.domain.oa.service.impl.RoleServiceImpl;
import com.domain.oa.utils.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Role)表控制层
 *
 * @author makejava
 * @since 2023-02-20 15:50:46
 */
@RestController
@RequestMapping("role")
public class RoleController {
    @Resource
    private RoleServiceImpl dataService;

    /**
     * 分页获取数据
     * @param pageCurrent
     * @param pageSize
     * @return ResultVo
     */
    @GetMapping("/page")
    public ResultVo getPage(@RequestParam Integer pageCurrent,
                            @RequestParam Integer pageSize) {
        return dataService.getDataByPage(pageCurrent, pageSize);
    }

    /**
     * 修改数据
     * @param data
     * @return ResultVo
     */
    @PostMapping
    public ResultVo editData(@RequestBody Role data) {
        return dataService.editData(data);
    }

    /**
     * 添加数据
     * @param data
     * @return
     */
    @PutMapping
    public ResultVo putData(@RequestBody Role data) {
        return dataService.editData(data);
    }

    /**
     * 删除数据
     * @param id
     * @return ResultVo
     */
    @DeleteMapping("/{id}")
    public ResultVo deleteData(@PathVariable Integer id) {
        return dataService.deleteDataById(id);
    }

    /**
     * 通过角色id获取当前角色所有权限
     * @param roleId
     * @return
     */
    @GetMapping("/{roleId}")
    public ResultVo getRoleMenuByRoleId(@PathVariable Integer roleId) {
        return dataService.getRoleMenuByRoleId(roleId);
    }


    /**
     * 添加权限
     * @param roleMenu
     * @return
     */
    @PostMapping("/add/menu")
    public ResultVo addRoleMenu(@RequestBody RoleMenu roleMenu) {
        return dataService.addRoleMenu(roleMenu.getRId(), roleMenu.getMId());
    }

    /**
     * 删除权限
     * @param roleMenu
     * @return
     */
    @PostMapping("/remove/menu")
    public ResultVo removeRoleMenu(@RequestBody RoleMenu roleMenu) {
        return dataService.removeRoleMenu(roleMenu.getRId(), roleMenu.getMId());
    }

    @GetMapping
    public ResultVo getAllRole() {
        return dataService.getAllRole();
    }

}

